home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIP Haziran 2001.iso / prog / haziran / 19 / setup.exe / data.z / speaker_gui.pas < prev    next >
Pascal/Delphi Source File  |  2001-04-11  |  3KB  |  99 lines

  1.  
  2. {////////////////////////////////////////////////////////////////
  3. // File - speaker_gui.pas
  4. //
  5. // This application plays a tone to the speaker, and is
  6. // controlled via a graphical user interface.
  7. // The speaker is accessed directly on the motherboard, using
  8. // WinDriver functions.
  9. //
  10. ////////////////////////////////////////////////////////////////}
  11.  
  12. unit speaker_gui;
  13.  
  14. interface
  15.  
  16. uses
  17.   Windows,  SysUtils, Classes, Controls, Forms,
  18.     windrvr , speaker_lib, ExtCtrls, StdCtrls;
  19.  
  20. type
  21.   TSpeaker_Form = class(TForm)
  22.     Chime_butten: TButton;
  23.     Tone_Butten: TButton;
  24.     Frequency: TEdit;
  25.     Duration: TEdit;
  26.     freq_label: TLabel;
  27.     dura_label: TLabel;
  28.     Exit_Butten: TButton;
  29.     About_Butten: TButton;
  30.     Shape2: TShape;
  31.     procedure Chime_buttenClick(Sender: TObject);
  32.     procedure Tone_ButtenClick(Sender: TObject);
  33.     procedure Exit_ButtenClick(Sender: TObject);
  34.     procedure About_ButtenClick(Sender: TObject);
  35.     procedure form_OnCreate(sender: TObject);
  36.   private
  37.     { Private declarations }
  38.   public
  39.     { Public declarations }
  40.   end;
  41.  
  42. var
  43.   Speaker_Form: TSpeaker_Form;
  44.   hSPEAKER: SPEAKER_HANDLE ;
  45. implementation
  46.  
  47. {$R *.DFM}
  48.  
  49. { play a simple chime }
  50. procedure TSpeaker_Form.Chime_buttenClick(Sender: TObject);
  51. begin
  52.   SPEAKER_Tone(hSpeaker, 440, 400);
  53.   SPEAKER_Tone(hSpeaker, 329, 200);
  54.   SPEAKER_Tone(hSpeaker, 1, 10);
  55.   SPEAKER_Tone(hSpeaker, 329, 200);
  56.   SPEAKER_Tone(hSpeaker, 369, 400);
  57.   SPEAKER_Tone(hSpeaker, 329, 800);
  58.   SPEAKER_Tone(hSpeaker, 415, 400);
  59.   SPEAKER_Tone(hSpeaker, 440, 600);
  60. end;
  61.  
  62. { play one tone according to input from the form }
  63. procedure TSpeaker_Form.Tone_ButtenClick(Sender: TObject);
  64. var
  65.   dwHertz: DWORD ;
  66.   dwMilli: DWORD ;
  67. begin
  68.   dwHertz:= DWORD (StrToInt(Frequency.Text));
  69.   dwMilli:= DWORD (StrToInt(Duration.Text));
  70.   SPEAKER_Tone(hSpeaker,dwHertz,dwMilli);
  71. end;
  72.  
  73. procedure TSpeaker_Form.Exit_ButtenClick(Sender: TObject);
  74. begin
  75.   if (SPEAKER_Open(hSPEAKER)) then
  76.     SPEAKER_Close(hSPEAKER);           { close the handle }
  77.   Close;
  78. end;
  79.  
  80. { shows an about box }
  81. procedure TSpeaker_Form.About_ButtenClick(Sender: TObject);
  82. begin
  83.   application.MessageBox(
  84.     'Speaker Sample v1.0'#13#10#13#10'This sample accesses the on-board speaker'#13#10'through the WinDriver'#180's Delphi interface.'#13#10#13#10'Copyright (c) 2001 Jungo'
  85.      ,PChar ('About the Speaker Sample'),MB_OK);
  86. end;
  87.  
  88. { opens a handle to the speaker }
  89. procedure TSpeaker_Form.form_OnCreate(sender: TObject);
  90. begin
  91.   hSPEAKER:= nil;
  92.   if  (not SPEAKER_Open(hSPEAKER)) then
  93.   begin
  94.     application.MessageBox(PChar (AnsiString(SPEAKER_ErrorString)),PChar ('ERROR'),MB_OK);
  95.     halt;
  96.   end ;
  97. end;
  98. end.
  99.